package com.yuqian.JavaSe.thread.cands;

import java.util.concurrent.LinkedBlockingDeque;

/**
 * 产品类
 * 生产者生产产品
 * 消费者消费产品
 * @author yy
 *
 */
public class Product <T>{
	//产品
	private LinkedBlockingDeque<T> products;
	//最多产品数
	private int maxSize;
	
	Product(int maxSize){
		this.maxSize = maxSize;
		this.products = new LinkedBlockingDeque<T>(maxSize);
	}

	public LinkedBlockingDeque<T> getProducts() {
		return products;
	}

	public int getMaxSize() {
		return maxSize;
	}
	
	
	public static void main(String[] args) {
		final Product<String> pro = new Product<String>(10);
		Thread cT = new Thread(new Runnable() {
			
			public void run() {
				// TODO Auto-generated method stub
				Customer<String>  c = new Customer<String>(pro);
				while(true) {
					c.consumeProduct();
				}
				
			}
		});
		Thread pT = new Thread(new Runnable() {
			
			public void run() {
				// TODO Auto-generated method stub
				Integer  k =1;
				Producer<String>  p = new Producer<String>(pro);
				while(true) {
					p.produceProduct( (k++)+"");
				}
			}
		});
		
		pT.start();
		cT.start();
 	}
}
